package LeetCode.month01.day30;

import java.util.Arrays;

public class No1208 {
    public static void main(String[] args) {
        System.out.println(equalSubstring("abcd","bcde",0));
    }
    public static int equalSubstring(String s, String t, int maxCost) {
        int n = s.length();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i]= Math.abs(s.charAt(i)-t.charAt(i));
        }
        int sum = 0;
        int left = 0;
        int res = 0;
        for (int i = 0; i < n; i++) {
            sum+=arr[i];
            while(sum>maxCost){
                sum-=arr[left];
                left++;
            }
            res = Math.max(res,i-left+1);
        }
        return Math.max(res,n-left);
    }
}
